import KZJRequest from '../index'
import { TRequestDefaultResult } from '../type'
import localCache from '@/utils/cache'
import { TUser } from './type'

enum Edit {
  users = '/user/update', // 歌曲
  avatar = '/avatar/upload'
}

export function updateUser(params: TUser) {
  return KZJRequest.get<TRequestDefaultResult>({
    url: Edit.users,
    params,
    showLoading: true,
    takeCookie: true,
    immediately: true
  })
}

export function updateAvatar(data: any, imgSize = 1012) {
  const cookie = localCache.getCache('cookie') ?? ''
  return KZJRequest.post<TRequestDefaultResult>({
    url: Edit.avatar,
    params: {
      imgSize,
      cookie
    },
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    showLoading: true,
    immediately: true
  })
}
